package com.example.llm.learn.reactiveweb.emplyee.service;

import com.example.llm.learn.reactiveweb.emplyee.dto.EmployeeDTO;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

@Service
public class EmployeeService implements InitializingBean {

    private Map<Integer, EmployeeDTO> employeeMap = new HashMap<>();

    @Override
    public void afterPropertiesSet() throws Exception {
        employeeMap.put(1, new EmployeeDTO(1, "张一"));
        employeeMap.put(2, new EmployeeDTO(2, "李二"));
        employeeMap.put(3, new EmployeeDTO(3, "王三"));
        employeeMap.put(4, new EmployeeDTO(4, "赵四"));
        employeeMap.put(5, new EmployeeDTO(5, "孙五"));
        employeeMap.put(6, new EmployeeDTO(6, "何六"));
        employeeMap.put(7, new EmployeeDTO(7, "艾七"));
    }

    public Mono<EmployeeDTO> getById(Integer id) {
        return Mono.just(employeeMap.get(id));
    }

    public Flux<EmployeeDTO> getList() {
        return Flux.fromIterable(employeeMap.values());
    }
}
